import request from "@/utils/request";

/**
 * 分页查询字典列表
 */
export async function pageDictionaries(params) {
  const res = await request.get("/system/dictionary/page", { params });
  if (res.data.code === 200) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 查询字典列表
 */
export async function listDictionaries(params) {
  const res = await request.get("/system/dictionary", {
    params,
  });
  if (res.data.code === 200) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 添加字典
 */
export async function addDictionary(data) {
  const res = await request.post("/system/dictionary", data);
  if (res.data.code === 200) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 获取字典
 */
export async function showDictionary(dict_id) {
  const res = await request.get("/system/dictionary/" + dict_id);
  if (res.data.code === 200) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 修改字典
 */
export async function updateDictionary(data) {
  const res = await request.put("/system/dictionary/" + data.dict_id, data);
  if (res.data.code === 200) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 删除字典
 */
export async function removeDictionary(data) {
  const res = await request.delete("/system/dictionary/batch", { data });
  if (res.data.code === 200) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}
